package com.xydtech.ecard.statistics.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.ShiroUtils;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.statistics.domain.EcardDeptChecking;
import com.xydtech.ecard.statistics.service.IEcardDeptCheckingService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 机构考勤统计Controller
 *
 * @author JHON
 * @date 2022-08-03
 */
@Controller
@RequestMapping("/statistics/deptChecking")
public class EcardDeptCheckingController extends BaseController {
    private String prefix = "statistics/deptChecking";

    @Autowired
    private IEcardDeptCheckingService ecardDeptCheckingService;

    @RequiresPermissions("statistics:deptChecking:view")
    @GetMapping("/{checkingType}")
    public String deptChecking(@PathVariable("checkingType") String checkingType, ModelMap mmap) {
        mmap.put("checkingType", checkingType);
        return prefix + "/deptChecking";
    }

    /**
     * 查询机构考勤统计列表
     */
    @RequiresPermissions("statistics:deptChecking:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardDeptChecking ecardDeptChecking) {
        if (ecardDeptChecking.getDeptId() == null) {
            ecardDeptChecking.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        if ("1".equals(ecardDeptChecking.getCheckingType())) {
            ecardDeptChecking.setDeptType("3");
        } else {
            ecardDeptChecking.setDeptType("4");
        }
        List<EcardDeptChecking> list = ecardDeptCheckingService.selectEcardDeptCheckingList(ecardDeptChecking);
        return getDataTable(list);
    }

    /**
     * 导出机构考勤统计列表
     */
    @RequiresPermissions("statistics:deptChecking:export")
    @Log(title = "机构考勤统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardDeptChecking ecardDeptChecking) {
        if (ecardDeptChecking.getDeptId() == null) {
            ecardDeptChecking.setDeptId(ShiroUtils.getSysUser().getDeptId());
        }
        if ("1".equals(ecardDeptChecking.getCheckingType())) {
            ecardDeptChecking.setDeptType("3");
        } else {
            ecardDeptChecking.setDeptType("4");
        }
        List<EcardDeptChecking> list = ecardDeptCheckingService.selectEcardDeptCheckingList(ecardDeptChecking);
        ExcelUtil<EcardDeptChecking> util = new ExcelUtil<EcardDeptChecking>(EcardDeptChecking.class);
        return util.exportExcel(list, "机构考勤统计数据");
    }
}
